package neanda.engine.core.window;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Toolkit;

import javax.swing.JFrame;

import neanda.engine.core.Game;
import neanda.engine.core.entity.Entity;
import neanda.engine.util.log.Log;
import neanda.engine.util.log.Logable;

public class Window extends JFrame implements Logable
{
	public static final int VIEW_MODE_FULLSCREEN = 1;
	public static final int VIEW_MODE_WINDOW	 = 2;
	
	private Log log = new Log();
	
	public Window(int view_mode, boolean logStatus)
	{
		log.setActiv(logStatus);
		log.logMessage("Window erstellt");
		this.setResizable(false);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.getContentPane().setBackground(Color.black);
		
		switch(view_mode)
		{
			case VIEW_MODE_FULLSCREEN:
			{
				log.logMessage("Mode.Fullscreen");
				this.setUndecorated(true);
				this.setBounds(0, 0, Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height);
				break;
			}
			case VIEW_MODE_WINDOW:
			{
				log.logMessage("Mode.Windowscreen");
				this.setBounds(0, 0, Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height);
				break;
			}
			default:
			{
				System.err.println("Unbekannter Viewmode!");
			}
		}
		this.setVisible(true);
	}

	/** Zeichnet alle Objekte ins Spiel **/
	public void drawObjects(Graphics g)
	{
		if(Game.entities.size() > 0)
		{
			for(Entity e:Game.entities)
			{
				e.drawObject(g);
			}
		}
	}
	
	@Override
	protected void paintComponent(Graphics g)
	{
		drawObjects(g);
	}
	
	@Override
	public void setLogStatus(boolean status)
	{
		log.setActiv(status);
	}
}
